/**
 * 
 */
package com.cipe.cmrs.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author Incepio
 * 
 */
public enum StreamUtil {
    INSTANCE;

    public static final int DEFAULT_BUFFER_SIZE = 8192;

    public void transfer(InputStream inputStream, OutputStream outputStream) throws IOException {
        transfer(inputStream, outputStream, DEFAULT_BUFFER_SIZE);
    }

    public void transfer(InputStream inputStream, OutputStream outputStream, int bufferSize) throws IOException {

        byte buf[] = new byte[bufferSize];

        int n = inputStream.read(buf);
        while (n != -1) {
            outputStream.write(buf, 0, n);
            n = inputStream.read(buf);
        }

        outputStream.flush();
    }
}